<style>
.a0 {
  background: #f0f0f0;
}
.s0 {
  color: #ccc;
}
.approve {
  color: green;
}
.admin {
  background:pink;
}

.w300 {
	width: 300px;
}

.h50 {
	height: 50px;
}

.bookForm > div {
	/*display: block;*/
	margin-bottom: 20px;
}
.bookForm >div label {
	display: inline-block;
	width: 100px;
	text-align: right;
	vertical-align: top;
}

.btn {
	border: none;
	background-color: #3b9ee1;
    border-color: #3b9ee1;
    font-size: 13px;
    margin-right: 10px;
    vertical-align: middle;
    padding: 6px 8px;
    color: #FFFFFF;
    border-radius: 4px;
}





</style>
<script>
function showResult(data) {
  if (data.code > 0){
	alert('操作错误: ' + data.message);
  }
  else {
	alert('操作成功');
  }
}

function setUpdate(data){
	console.log(data);
}

function setStatus(id, val){
  val = prompt('请输入状态值', val);
  if (val !== null) {
	var url = '?uri=/admin/maintain/updateUser&t=status&id='+id+'&v='+encodeURIComponent(val);
	$.getJSON(url, showResult);
  }
}
function setDepartment(id, val){
  val = prompt('请输入状态值', val);
  if (val !== null) {
	var url = '?uri=/admin/maintain/updateUser&t=department&id='+id+'&v='+encodeURIComponent(val);
	$.getJSON(url, showResult);
  }
}
function setAcl(id, val){
  val = prompt('请输出新的权限列表，英文逗号[,]分隔', val);
  if (val !== null) {
	var url = '?uri=/admin/maintain/updateUser&t=acl&id='+id+'&v='+encodeURIComponent(val);
	$.getJSON(url, showResult);
  }
}
</script>
<table width="100%">
  <thead>
	<tr>
	  <th>ID</th>
	  <th>书名</th>
	  <th>作者</th>
	  <th>推荐序</th>
	  <th>封面</th>
	  <th>状态</th>
	  <th>操作</th>
	</tr>
  </thead>
  <tbody>
  <?php $a=0; foreach ($list as $book): $id=$book['_id']; ?>
	<tr class="a<?=($a++)%2;?> s<?=$book['status']?>">
	  <td><?=$id;?></td>
	  <td><?=htmlspecialchars($book['title']);?></td>
	  <td><?=htmlspecialchars($book['author']);?></td>
	  <td><div><?=htmlspecialchars($book['desc']);?></div></td>
	  <td><img href="<?=$book['cover'];?>"/></td>
	  <td><?=$book['isDeleted'] ? '删除' : '使用中';?></td>
	  <td align="center">
		<a href="#" onclick="setUpdate(<?='$book';?>);return !1;">编辑</a> |
		<a href="#" onclick="setDepartment(<?=$id;?>, '<?=$dp?>');return !1;">部门</a> |
		<a href="#" onclick="setAcl(<?=$id;?>, '<?=join(',', $book['acl'])?>'); return !1;">权限</a>
	  </td>
	</tr>
  <?php endforeach; ?>
  </tbody>
</table>

<br/>
<br/>
<br/>

<form action="?uri=/admin/addBook" method="post" enctype="multipart/form-data" class="bookForm">
	<div>
		<label for="title">书名：</label>
		<input type="text" name="title" class="w300"/>
	</div>
	<div>
		<label for="author">作者：</label>
		<input type="text" name="author" class="w300"/>
	</div>
	<div>
		<label for="desc">推荐序：</label>
		<textarea name="desc" rows="5" cols="60"></textarea>
	</div>
	<div>
		<label for="cover">封面：</label>
		<input type="file" name="cover"/>
	</div>
	<div>
		<label></label>
		<input type="submit" value="提交" class="btn"/>
	</div>
</form>